package com.kdtech.analyse.video;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;

import com.kdtech.crawler.CrawlHTML;
import com.kdtech.entity.crawler.UrlMeta;
import com.kdtech.entity.data.NewsMeta;
import com.kdtech.utils.DateUtils;
import com.kdtech.utils.NumberUtils;
import com.kdtech.utils.StringUtils;
import com.kdtech.analyse.AnalyseNews;

/**
 *  上饶电视台 解析类
 * 
 * @author Chase
 * 
 */
public class LetvVideoAnalyse implements AnalyseNews {



	
	public boolean isDetailPage(String url) {
		boolean bRet = false;
		String[] regex = {
				//http://www.letv.com/ptv/vplay/23421383.html
				"http://www.letv.com/([a-z]*/){0,}[0-9]*.html"
				};
		for (int i = 0; i < regex.length; i++) {
			if (url.matches(regex[i])) {
				return true;
			}
		}
		return bRet;
	}	

	
	public NewsMeta parserHtml(UrlMeta urlMeta) {

		String url = urlMeta.getUrl(); 

		/*
		 * 定义新闻实体需要的字段
		 */
		String title = null;
		String desc = null;
		String author = null;
		Long dateLong = null;
		String htmltxt = urlMeta.getHtml();
		Document doc = Jsoup.parse(htmltxt);
		title = doc.select("h1.j-video-name").text();
		if(StringUtils.isBlank(title)){
			title = StringUtils.substringBefore(doc.select("title").text(), "-");
		}		
		desc = doc.select("p.limit_txt").text();
		if(StringUtils.isBlank(desc)){
			desc = doc.select("ul.intro_box li.Li04").attr("alltext");
		}		
		if(StringUtils.isBlank(desc)){
			desc = doc.select("div#content").text();
		}		
		dateLong = DateUtils.matchDate(doc.select("li.li_04").text());
		if(dateLong==null){
			dateLong = DateUtils.matchDate(doc.select("ul.intro_box li.Li01").text());
		}
		if(dateLong==null){
			dateLong = DateUtils.matchDate(title);
		}
		if(dateLong==null){
			dateLong = System.currentTimeMillis();
		}
		NewsMeta meta = new NewsMeta();
		meta.setTitle(title);
		meta.setContent(desc);
		meta.setAuthor(author);
		meta.setUrl(url);
		meta.setType(2);
		
		meta.setDate(dateLong);
			
		return meta;
		
	}
	
	
	public NewsMeta Update(NewsMeta meta) {
		return null;
	}


	
}
